/* File:       downloader.h
* Function:    supply the SMS download function
* Creator:     WKW
* Data:        2010.02.26
* status:      create
* History:
*/


#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h> 

#include <pthread.h>

#include <glib.h>

#define DOWNLOADER_DEFAULT_DATA_LEN 4096*1024

typedef struct _Downloader
{
	char *url;
	char *out_file;
	char *data;
	int data_len;
	int data_seek;
	int download_progress;
	
	pthread_t thread_id;
	int timer;
	int err_id;
	
	gpointer user_data;
	
	FILE *out;
	
	gboolean (*progress_func)(struct _Downloader * dwonloader,gpointer data);
	gboolean (*finished_func)(struct _Downloader * dwonloader,gpointer data);
	gboolean (*error_func)( struct _Downloader * dwonloader,gpointer data); 
	
}Downloader;

void downloader_global_init(int argc ,char **argv);
void downloader_global_cleanup();
Downloader * downloader_new(const char *url,const char *out_file,int data_len,
							gpointer user_data);
void downloader_delete(Downloader *downloader);
gboolean downloader_set_func(Downloader *downloader,const char *key,
							 gboolean (*func)(Downloader* dwonloader,gpointer data));
void downloader_run(Downloader *dwonloader);
void  downloader_stop(Downloader *downloader,gboolean delete);
